const Uniq = require("../template")

function testUniqComplexScenarios() {
  console.log(
    "1. 数组去重复杂场景 - 嵌套数组去重:",
    (() => {
      const array = [
        [1, 2, 3],
        [1, 2, 3],
        [4, 5, 6],
        [1, 2, 3],
        [7, 8, 9]
      ]
      const result = Uniq.uniqDeep(array, 1)
      return result.length === 3 // 应该去重到3个不同的数组
    })()
  )

  console.log(
    "2. 数组去重复杂场景 - 多层嵌套对象:",
    (() => {
      const array = [
        { a: { b: { c: 1 } } },
        { a: { b: { c: 2 } } },
        { a: { b: { c: 1 } } },
        { a: { b: { c: 3 } } }
      ]
      const result = Uniq.uniqBy(array, 'a.b.c')
      return result.length === 3 // 根据深层属性去重
    })()
  )

  console.log(
    "3. 数组去重复杂场景 - 混合数据类型:",
    (() => {
      const array = [
        1, '1', true, 'true', null, undefined, 
        { id: 1 }, { id: 1 }, { id: 2 },
        [1, 2], [1, 2], [3, 4],
        () => {}, () => {}, () => {}
      ]
      const result = Uniq.uniq(array)
      return result.length === 12 // 12种不同的值
    })()
  )

  console.log(
    "4. 数组去重复杂场景 - 条件组合去重:",
    (() => {
      const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
      const result = Uniq.uniqWith(array, (a, b) => {
        return a % 3 === b % 3 && a % 2 === b % 2
      })
      return result.length === 4 // 4种不同的组合
    })()
  )

  console.log(
    "5. 数组去重复杂场景 - 多条件去重:",
    (() => {
      const array = [
        { id: 1, type: 'A', value: 100 },
        { id: 2, type: 'B', value: 200 },
        { id: 1, type: 'A', value: 100 },
        { id: 3, type: 'A', value: 300 },
        { id: 1, type: 'B', value: 100 }
      ]
      const result = Uniq.uniqBy(array, 'id')
      return result.length === 3 // 根据id去重
    })()
  )

  console.log(
    "6. 数组去重复杂场景 - 函数去重:",
    (() => {
      const fn1 = (x) => x * 2
      const fn2 = (x) => x * 2
      const fn3 = (x) => x * 3
      const array = [fn1, fn2, fn3, fn1]
      const result = Uniq.uniq(array)
      return result.length === 3 // 函数引用去重
    })()
  )

  console.log(
    "7. 数组去重复杂场景 - 正则表达式去重:",
    (() => {
      const regex1 = /test/g
      const regex2 = /test/g
      const regex3 = /test/i
      const array = [regex1, regex2, regex3, regex1]
      const result = Uniq.uniq(array)
      return result.length === 3 // 正则表达式去重
    })()
  )

  console.log(
    "8. 数组去重复杂场景 - 日期对象去重:",
    (() => {
      const date1 = new Date('2023-01-01')
      const date2 = new Date('2023-01-01')
      const date3 = new Date('2023-01-02')
      const array = [date1, date2, date3, date1]
      const result = Uniq.uniq(array)
      return result.length === 3 // 日期对象去重
    })()
  )

  console.log(
    "9. 数组去重复杂场景 - 循环引用对象:",
    (() => {
      const obj1 = { id: 1 }
      const obj2 = { id: 2 }
      obj1.ref = obj1
      obj2.ref = obj2
      const array = [obj1, obj2, obj1]
      const result = Uniq.uniq(array)
      return result.length === 2 // 循环引用对象去重
    })()
  )

  console.log(
    "10. 数组去重复杂场景 - 特殊值处理:",
    (() => {
      const array = [
        NaN, NaN, Infinity, -Infinity, Infinity,
        0, -0, 0, -0,
        '', '', ' ', ' ',
        null, null, undefined, undefined
      ]
      const result = Uniq.uniq(array)
      return result.length === 8 // 8种不同的特殊值
    })()
  )

  console.log(
    "11. 数组去重复杂场景 - 大数处理:",
    (() => {
      const array = [
        Number.MAX_SAFE_INTEGER,
        Number.MAX_SAFE_INTEGER,
        Number.MIN_SAFE_INTEGER,
        Number.MIN_SAFE_INTEGER,
        9007199254740991,
        9007199254740991
      ]
      const result = Uniq.uniq(array)
      return result.length === 3 // 3种不同的大数
    })()
  )

  console.log(
    "12. 数组去重复杂场景 - 符号去重:",
    (() => {
      const sym1 = Symbol('test')
      const sym2 = Symbol('test')
      const sym3 = Symbol('other')
      const array = [sym1, sym2, sym3, sym1]
      const result = Uniq.uniq(array)
      return result.length === 3 // 符号去重
    })()
  )

  console.log(
    "13. 数组去重复杂场景 - 类实例去重:",
    (() => {
      class TestClass {
        constructor(id) { this.id = id }
      }
      const instance1 = new TestClass(1)
      const instance2 = new TestClass(1)
      const instance3 = new TestClass(2)
      const array = [instance1, instance2, instance3, instance1]
      const result = Uniq.uniq(array)
      return result.length === 3 // 类实例去重
    })()
  )

  console.log(
    "14. 数组去重复杂场景 - 异步去重:",
    (() => {
      const array = [1, 2, 2, 3, 3, 3, 4, 5, 5]
      return Uniq.uniqAsync(array, async x => x * 2).then(result => {
        return result.length === 5 // 异步去重应该正确
      })
    })()
  )

  console.log(
    "15. 数组去重复杂场景 - 并发去重:",
    (() => {
      const array = [1, 2, 2, 3, 3, 3, 4, 5, 5]
      return Uniq.uniqConcurrent(array, async x => x * 2, 3).then(result => {
        return result.length === 5 // 并发去重应该正确
      })
    })()
  )

  console.log(
    "16. 数组去重复杂场景 - 统计去重:",
    (() => {
      const array = [1, 2, 2, 3, 3, 3, 4, 5, 5]
      const result = Uniq.uniqWithStats(array)
      return result.result.length === 5 && typeof result.stats === 'object'
    })()
  )

  console.log(
    "17. 数组去重复杂场景 - 边界条件:",
    (() => {
      const array = [null, undefined, null, undefined]
      const result = Uniq.uniq(array)
      return result.length === 2 // null和undefined应该被区分
    })()
  )

  console.log(
    "18. 数组去重复杂场景 - 性能边界:",
    (() => {
      const largeArray = Array.from({ length: 100000 }, (_, i) => i % 1000)
      const start = performance.now()
      const result = Uniq.uniq(largeArray)
      const end = performance.now()
      return (end - start) < 1000 && result.length === 1000 // 10万条数据应该在1秒内完成
    })()
  )
}

testUniqComplexScenarios()
